package com.bite.common.core.domain;

import com.bite.common.core.enums.ResultCode;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

@Data
@NoArgsConstructor
public class TableDataInfo {
    private int code; // 响应码
    private String msg; // 响应消息
    private long total; // 总个数
    private List<?> rows; // 数据列表

    public static TableDataInfo empty() {
        return assemble(List.of(), 0, ResultCode.SUCCESS);
    }

    public static TableDataInfo success(List<?> rows, long total) {
        return assemble(rows, total, ResultCode.SUCCESS);
    }



    private static TableDataInfo assemble(List<?> rows, long total, ResultCode resultCode) {
        TableDataInfo data = new TableDataInfo();
        data.setCode(resultCode.getCode());
        data.setMsg(resultCode.getMsg());
        data.setTotal(total);
        data.setRows(rows);
        return data;
    }
}
